package com.silp.labs.cacticlient;

import java.io.IOException;

import org.ksoap2.SoapEnvelope;
import org.ksoap2.SoapFault;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;
import org.xmlpull.v1.XmlPullParserException;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.util.Base64;

public class Sendrequest {
	
	private static final String NAMESPACE = "http://monitor.webgame.vn/";
	private static final String URL = "http://monitor.webgame.vn/plugins/nmidWebService/webservice.php";
	
	
	public static String sendgetTree(String ws_password) throws SoapFault{
		String SOAP_ACTION = "http://monitor.webgame.vn/plugins/nmidWebService/webservice.php/getTree";
		String METHOD_NAME = "getTree";
		SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
		SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
		envelope.setOutputSoapObject(request);
		request.addProperty("ws_password",ws_password);
		HttpTransportSE ht = new HttpTransportSE(URL);
		try {
			ht.call(SOAP_ACTION, envelope);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (XmlPullParserException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		 Object reponse = envelope.getResponse();
		String result = reponse.toString();
		
		return result;
	}
	public static Bitmap sendgetGraph(String ws_password,int graph_id, int start, int end , int height, int width) throws SoapFault{
		String SOAP_ACTION = "http://monitor.webgame.vn/plugins/nmidWebService/webservice.php/getGraph";
		String METHOD_NAME = "getGraph";
		SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
		SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
		envelope.setOutputSoapObject(request);
		request.addProperty("ws_password",ws_password);
		request.addProperty("id",graph_id);
		request.addProperty("start",start);
		request.addProperty("end",end);
		request.addProperty("height",height);
		request.addProperty("widtgh",width);
		HttpTransportSE ht = new HttpTransportSE(URL);
		try {
			ht.call(SOAP_ACTION, envelope);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (XmlPullParserException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		Object result = envelope.getResponse();
		String reponse = result.toString();
		byte[] decodedString = Base64.decode(reponse.getBytes(), Base64.DEFAULT);
		 Bitmap b = BitmapFactory.decodeByteArray(decodedString, 0, decodedString.length);
		
		return b;
	}
	public static String sendgetDownHosts(String ws_password) throws SoapFault{
		String SOAP_ACTION = "http://monitor.webgame.vn/plugins/nmidWebService/webservice.php/getDownHosts";
		String METHOD_NAME = "getDownHosts";
		SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
		SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
		envelope.setOutputSoapObject(request);
		request.addProperty("ws_password",ws_password);
		HttpTransportSE ht = new HttpTransportSE(URL);
		try {
			ht.call(SOAP_ACTION, envelope);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (XmlPullParserException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		Object result = envelope.getResponse();
		String reponse = result.toString();
		return reponse;
	}
}
